//
//  GetOrderDetailViewController.m
//  Hui
//
//  Created by HawkingWang on 16/10/31.
//  Copyright © 2016年 Hui. All rights reserved.
//

#import "GetOrderDetailViewController.h"

@interface GetOrderDetailViewController ()
/**订单标题*/
@property (weak, nonatomic) IBOutlet UILabel *orderTitle;
/**取送地址*/
@property (weak, nonatomic) IBOutlet UILabel *takeAddress;
@property (weak, nonatomic) IBOutlet UILabel *deliveryAddress;
/**抢单距离*/
@property (weak, nonatomic) IBOutlet UILabel *distance;
/**待取货 待配送 距离目的地*/
@property (weak, nonatomic) IBOutlet UILabel *distanceToDestination;

/**配送费*/
@property (weak, nonatomic) IBOutlet UILabel *money;
/**派单人*/
@property (weak, nonatomic) IBOutlet UILabel *publisherName;
@property (weak, nonatomic) IBOutlet UILabel *publisherTime;
@property (weak, nonatomic) IBOutlet UIButton *callPublisher;
/**收货人*/
@property (weak, nonatomic) IBOutlet UILabel *consigneeName;
@property (weak, nonatomic) IBOutlet UILabel *consigneeTime;
@property (weak, nonatomic) IBOutlet UIButton *callConsignee;

//抢单
@property (weak, nonatomic) IBOutlet UIButton *getOrderBtn;//立即抢单
//待取货
@property (weak, nonatomic) IBOutlet UIView *takeView;
@property (weak, nonatomic) IBOutlet UIButton *confirmTakeBtn;//确认取货
@property (weak, nonatomic) IBOutlet UIButton *cancleOrder;//取消订单
//待配送
@property (weak, nonatomic) IBOutlet UIButton *confirmDeliveryBtn;//确认送达
//已送达
@property (weak, nonatomic) IBOutlet UIButton *hasBeenDeliveryBtn;//已送达


/**地图*/
@property (weak, nonatomic) IBOutlet UIView *mapView;

@end

@implementation GetOrderDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setNav];
    
    switch (self.state) {
        case 0:
            [self getOrderSetting];
            break;
        case 1:
            [self takeSetting];
            break;
        case 2:
            [self deliverySetting];
            break;
        case 3:
            [self hasBeenDeliveredSetting];
            break;
        default:
            break;
    }
    
    _callPublisher.layer.borderWidth = 0.5;
    _callConsignee.layer.borderWidth = 0.5;
}

- (void)setNav{
    UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 24)];
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 2, 12, 20)];
    imageView.image = [UIImage imageNamed:@"top-back-w"];
    [leftView addSubview:imageView];
    UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 60, 60)];
    [leftBtn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [leftView addSubview:leftBtn];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftView];
    self.navigationItem.leftBarButtonItem = leftItem;
}



#pragma mark === 抢单 ===
- (void)getOrderSetting{
    _distance.hidden = NO;
    _distanceToDestination.hidden = YES;
    
    _getOrderBtn.hidden = NO;
    _takeView.hidden = YES;
    _confirmDeliveryBtn.hidden = YES;
    _hasBeenDeliveryBtn.hidden = YES;
    
    _callPublisher.layer.borderColor = RGBCOLOR(191, 197, 201).CGColor;
    [_callPublisher setTitleColor:RGBCOLOR(191, 197, 201) forState:UIControlStateNormal];
    _callPublisher.userInteractionEnabled = NO;
    _callConsignee.layer.borderColor = RGBCOLOR(191, 197, 201).CGColor;
    [_callConsignee setTitleColor:RGBCOLOR(191, 197, 201) forState:UIControlStateNormal];
    _callConsignee.userInteractionEnabled = NO;
}
/**立即抢单*/
- (IBAction)getOrder:(id)sender {
    [SVProgressHUD show];
    [SVProgressHUD showSuccessWithStatus:@"抢单成功"];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [SVProgressHUD dismiss];
        [self takeSetting];
    });
}

#pragma mark === 待取货 ===
- (void)takeSetting{
    _distance.hidden = YES;
    _distanceToDestination.hidden = NO;
    _distanceToDestination.text = @"距离取货目的地1.2km";
    
    _getOrderBtn.hidden = YES;
    _takeView.hidden = NO;
    _confirmDeliveryBtn.hidden = YES;
    _hasBeenDeliveryBtn.hidden = YES;
    
    _callPublisher.layer.borderColor = APPCOLOR.CGColor;
    [_callPublisher setTitleColor:APPCOLOR forState:UIControlStateNormal];
    _callPublisher.userInteractionEnabled = YES;
    _callConsignee.layer.borderColor = RGBCOLOR(253, 151, 52).CGColor;
    [_callConsignee setTitleColor:RGBCOLOR(253, 151, 52) forState:UIControlStateNormal];
    _callConsignee.userInteractionEnabled = YES;
}
/**确认取货*/
- (IBAction)confirmTakeGood:(id)sender {
    [SVProgressHUD show];
    [SVProgressHUD showSuccessWithStatus:@"已确认收货"];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [SVProgressHUD dismiss];
        [self deliverySetting];
    });
}
/**取消订单*/
- (IBAction)cancleOrder:(id)sender {
    [SVProgressHUD show];
    [SVProgressHUD showSuccessWithStatus:@"订单已取消"];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [SVProgressHUD dismiss];
        [self getOrderSetting];
    });
}

#pragma mark === 待配送 ===
- (void)deliverySetting{
    _distance.hidden = YES;
    _distanceToDestination.hidden = NO;
    _distanceToDestination.text = @"距离送货目的地1.2km";
    
    _getOrderBtn.hidden = YES;
    _takeView.hidden = YES;
    _confirmDeliveryBtn.hidden = NO;
    _hasBeenDeliveryBtn.hidden = YES;
    
    _callPublisher.layer.borderColor = APPCOLOR.CGColor;
    [_callPublisher setTitleColor:APPCOLOR forState:UIControlStateNormal];
    _callPublisher.userInteractionEnabled = YES;
    _callConsignee.layer.borderColor = RGBCOLOR(253, 151, 52).CGColor;
    [_callConsignee setTitleColor:RGBCOLOR(253, 151, 52) forState:UIControlStateNormal];
    _callConsignee.userInteractionEnabled = YES;
}
/**确认送达*/
- (IBAction)confirmDelivery:(id)sender {
    [SVProgressHUD show];
    [SVProgressHUD showSuccessWithStatus:@"已确认送达"];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [SVProgressHUD dismiss];
        [self hasBeenDeliveredSetting];
    });
}

#pragma mark === 已送达 ===
- (void)hasBeenDeliveredSetting{
    _distance.hidden = YES;
    _distanceToDestination.hidden = NO;
    _distanceToDestination.text = @"本次配送已完成";
    
    _getOrderBtn.hidden = YES;
    _takeView.hidden = YES;
    _confirmDeliveryBtn.hidden = YES;
    _hasBeenDeliveryBtn.hidden = NO;
    
    _callPublisher.layer.borderColor = APPCOLOR.CGColor;
    [_callPublisher setTitleColor:APPCOLOR forState:UIControlStateNormal];
    _callPublisher.userInteractionEnabled = YES;
    _callConsignee.layer.borderColor = RGBCOLOR(253, 151, 52).CGColor;
    [_callConsignee setTitleColor:RGBCOLOR(253, 151, 52) forState:UIControlStateNormal];
    _callConsignee.userInteractionEnabled = YES;
}

- (void)back{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
